<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>最简单的上传下载</title>
<script type="text/javascript" src="js/jquery-1.6.3.js"></script>
</head>
<body onload="load()">
	<h1>Upload and download file demo by jspsmartupload</h1>
	<h5>Author: chen.simoncook. on 2011/09/10</h5>
	<hr>
	<div>
		<form enctype="multipart/form-data" method="post"
			name="simpleUploadFile" action="uploadFileAction"
			id="simpleUploadFile">
			<input id="uploadFileInput" type="file" name="testFile" size="40">
			<input id="confirmUploadFileBut" type="button" value="Confirm"
				onclick="uploadFile()">
		</form>
	</div>
</body>
<script type="text/javascript">
	var uuid4uploadFile = "";
	var uuid = (function() {
		var a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
				.split("");
		return function(b, f) {
			var h = a, e = [], d = Math.random;
			f = f || h.length;
			if (b) {
				for ( var c = 0; c < b; c++) {
					e[c] = h[0 | d() * f];
				}
			} else {
				var g;
				e[8] = e[13] = e[18] = e[23] = "-";
				e[14] = "4";
				for ( var c = 0; c < 36; c++) {
					if (!e[c]) {
						g = 0 | d() * 16;
						e[c] = h[(c == 19) ? (g & 3) | 8 : g & 15];
					}
				}
			}
			return e.join("").toLowerCase();
		};
	})();

	function load()
	{
		try
		{
			var res = '${uploadRes}' ;
			alert(res);
	
			if(res == 'success')
			{
				alert('UploadOK!');
			}
		}
		catch(e)
		{
			alert(e);
		}
	}

	// 提交需要上传的文件
	function uploadFile() {
		try {
			document.getElementById('confirmUploadFileBut').disable = true;
			uuid4uploadFile = uuid();
			var browseFileForm = document.getElementById('simpleUploadFile');
			var fileInputObj = document.getElementById('uploadFileInput');
			if (fileInputObj.value == "") {
				alert("Please choose a file to upload!");
				return;
			}
			browseFileForm.submit();
			alert(uuid());
			document.getElementById('confirmUploadFileBut').disable = false;
		} catch (e) {
			alert(e);
		}

	}
</script>

</html>